// VBConversions Note: VB project level imports
using System.Diagnostics;
using System;
using System.Xml.Linq;
using System.Windows.Forms;
using System.Collections;
using System.Drawing;
using Microsoft.VisualBasic;
using System.Data;
using System.Collections.Generic;
using Microsoft.VisualBasic.Compatibility;
using System.Linq;
// End of VB project level imports

using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
//using System.Windows.Forms.ToolStripRenderer;

namespace 喷码数据生成工具
{
	public class MenuSkin : System.Windows.Forms.ToolStripRenderer
	{
		public MenuSkin()
		{
			// VBConversions Note: Non-static class variable initialization is below.  Class variables cannot be initially assigned non-static values in C#.
			mMenuBorderColor = Color.FromArgb(255, 32, 107, 32);
			mItemBorderColor = Color.FromArgb(255, 32, 107, 32);
			mItemColor1 = Color.FromArgb(255, 243, 248, 237);
			mItemColor2 = Color.FromArgb(255, 172, 207, 125);
			mItemColor3 = Color.FromArgb(255, 218, 233, 197);
			mItemColor4 = Color.FromArgb(255, 250, 252, 247);
			mItemColor5 = Color.FromArgb(255, 255, 255);
			mItemDownColor1 = Color.FromArgb(255, 245, 202, 154);
			mItemDownColor2 = Color.FromArgb(255, 251, 177, 106);
			mItemDownColor3 = Color.FromArgb(255, 249, 154, 54);
			mItemDownColor4 = Color.FromArgb(255, 253, 240, 175);
			mItemDownColor5 = Color.White;
			mMenuBarColor1 = Color.FromArgb(178, 211, 135);
			mMenuBarColor2 = Color.FromArgb(178, 211, 135);
			mMenuBarColor3 = Color.FromArgb(178, 211, 135);
			mMenuBarColor4 = Color.FromArgb(178, 211, 135);
			mMenuBackColor = Color.White;
			mBackLeftColor1 = Color.FromArgb(174, 208, 128);
			mBackLeftColor2 = Color.FromArgb(226, 238, 210);
			mBackLeftColor3 = Color.FromArgb(232, 242, 220);
			mBackLeftColor4 = Color.FromArgb(255, 255, 255);
			mSeparator = Color.FromArgb(255, 204, 199, 186);
			mMenuCheck = global::My.Resources.menu_check;
			
		}
		private bool mAttachSkin = true;
		private Color mMenuBorderColor; // VBConversions Note: Initial value cannot be assigned here since it is non-static.  Assignment has been moved to the class constructors.
		private Color mItemBorderColor; // VBConversions Note: Initial value cannot be assigned here since it is non-static.  Assignment has been moved to the class constructors.
		private Color mItemColor1; // VBConversions Note: Initial value cannot be assigned here since it is non-static.  Assignment has been moved to the class constructors.
		private Color mItemColor2; // VBConversions Note: Initial value cannot be assigned here since it is non-static.  Assignment has been moved to the class constructors.
		private Color mItemColor3; // VBConversions Note: Initial value cannot be assigned here since it is non-static.  Assignment has been moved to the class constructors.
		private Color mItemColor4; // VBConversions Note: Initial value cannot be assigned here since it is non-static.  Assignment has been moved to the class constructors.
		private Color mItemColor5; // VBConversions Note: Initial value cannot be assigned here since it is non-static.  Assignment has been moved to the class constructors.
		private Color mItemDownColor1; // VBConversions Note: Initial value cannot be assigned here since it is non-static.  Assignment has been moved to the class constructors.
		private Color mItemDownColor2; // VBConversions Note: Initial value cannot be assigned here since it is non-static.  Assignment has been moved to the class constructors.
		private Color mItemDownColor3; // VBConversions Note: Initial value cannot be assigned here since it is non-static.  Assignment has been moved to the class constructors.
		private Color mItemDownColor4; // VBConversions Note: Initial value cannot be assigned here since it is non-static.  Assignment has been moved to the class constructors.
		private Color mItemDownColor5; // VBConversions Note: Initial value cannot be assigned here since it is non-static.  Assignment has been moved to the class constructors.
		private Color mMenuBarColor1; // VBConversions Note: Initial value cannot be assigned here since it is non-static.  Assignment has been moved to the class constructors.
		private Color mMenuBarColor2; // VBConversions Note: Initial value cannot be assigned here since it is non-static.  Assignment has been moved to the class constructors.
		private Color mMenuBarColor3; // VBConversions Note: Initial value cannot be assigned here since it is non-static.  Assignment has been moved to the class constructors.
		private Color mMenuBarColor4; // VBConversions Note: Initial value cannot be assigned here since it is non-static.  Assignment has been moved to the class constructors.
		private Color mMenuBackColor; // VBConversions Note: Initial value cannot be assigned here since it is non-static.  Assignment has been moved to the class constructors.
		private Color mBackLeftColor1; // VBConversions Note: Initial value cannot be assigned here since it is non-static.  Assignment has been moved to the class constructors.
		private Color mBackLeftColor2; // VBConversions Note: Initial value cannot be assigned here since it is non-static.  Assignment has been moved to the class constructors.
		private Color mBackLeftColor3; // VBConversions Note: Initial value cannot be assigned here since it is non-static.  Assignment has been moved to the class constructors.
		private Color mBackLeftColor4; // VBConversions Note: Initial value cannot be assigned here since it is non-static.  Assignment has been moved to the class constructors.
		private Color mSeparator; // VBConversions Note: Initial value cannot be assigned here since it is non-static.  Assignment has been moved to the class constructors.
		private int TLeft;
		private Bitmap mMenuCheck; // VBConversions Note: Initial value cannot be assigned here since it is non-static.  Assignment has been moved to the class constructors.
		private bool mFullSelected = true;
		private int mR = 3;
#region 自定义属性
public Color Separator
		{
			get
			{
				return mSeparator;
			}
			set
			{
				mSeparator = value;
			}
		}
public Color MenuBackColor
		{
			get
			{
				return mMenuBackColor;
			}
			set
			{
				mMenuBackColor = value;
			}
		}
public Color BackLeftColor4
		{
			get
			{
				return mBackLeftColor4;
			}
			set
			{
				mBackLeftColor4 = value;
			}
		}
public Color BackLeftColor3
		{
			get
			{
				return mBackLeftColor3;
			}
			set
			{
				mBackLeftColor3 = value;
			}
		}
public Color BackLeftColor2
		{
			get
			{
				return mBackLeftColor2;
			}
			set
			{
				mBackLeftColor2 = value;
			}
		}
public Color BackLeftColor1
		{
			get
			{
				return mBackLeftColor1;
			}
			set
			{
				mBackLeftColor1 = value;
			}
		}
public Color MenuBarColor4
		{
			get
			{
				return mMenuBarColor4;
			}
			set
			{
				mMenuBarColor4 = value;
			}
		}
public Color MenuBarColor3
		{
			get
			{
				return mMenuBarColor3;
			}
			set
			{
				mMenuBarColor3 = value;
			}
		}
public Color MenuBarColor2
		{
			get
			{
				return mMenuBarColor2;
			}
			set
			{
				mMenuBarColor2 = value;
			}
		}
public Color MenuBarColor1
		{
			get
			{
				return mMenuBarColor1;
			}
			set
			{
				mMenuBarColor1 = value;
			}
		}
public Color ItemDownColor5
		{
			get
			{
				return mItemDownColor5;
			}
			set
			{
				mItemDownColor5 = value;
			}
		}
public Color ItemDownColor4
		{
			get
			{
				return mItemDownColor4;
			}
			set
			{
				mItemDownColor4 = value;
			}
		}
public Color ItemDownColor3
		{
			get
			{
				return mItemDownColor3;
			}
			set
			{
				mItemDownColor3 = value;
			}
		}
public Color ItemDownColor2
		{
			get
			{
				return mItemDownColor2;
			}
			set
			{
				mItemDownColor2 = value;
			}
		}
public Color ItemDownColor1
		{
			get
			{
				return mItemDownColor1;
			}
			set
			{
				mItemDownColor1 = value;
			}
		}
public Color ItemColor5
		{
			get
			{
				return mItemColor5;
			}
			set
			{
				mItemColor5 = value;
			}
		}
public Color ItemColor4
		{
			get
			{
				return mItemColor4;
			}
			set
			{
				mItemColor4 = value;
			}
		}
public Color ItemColor3
		{
			get
			{
				return mItemColor3;
			}
			set
			{
				mItemColor3 = value;
			}
		}
public Color ItemColor2
		{
			get
			{
				return mItemColor2;
			}
			set
			{
				mItemColor2 = value;
			}
		}
public Color ItemColor1
		{
			get
			{
				return mItemColor1;
			}
			set
			{
				mItemColor1 = value;
			}
		}
public Color ItemBorderColor
		{
			get
			{
				return mItemBorderColor;
			}
			set
			{
				mItemBorderColor = value;
			}
		}
public Color MenuBorderColor
		{
			get
			{
				return mMenuBorderColor;
			}
			set
			{
				mMenuBorderColor = value;
			}
		}
#endregion
		private void MenuSkin_RenderButtonBackground(object sender, System.Windows.Forms.ToolStripItemRenderEventArgs e)
		{
			if (mAttachSkin == false)
			{
				return;
			}
			Graphics g = e.Graphics;
			ToolStripItem mItem = e.Item;
			
		}
		
		private void MenuSkin_RenderItemBackground(object sender, System.Windows.Forms.ToolStripItemRenderEventArgs e)
		{
			
			System.Text.StringBuilder messageBoxVB = new System.Text.StringBuilder();
			messageBoxVB.AppendFormat("{0} = {1}", "Graphics", e.Graphics);
			messageBoxVB.AppendLine();
			messageBoxVB.AppendFormat("{0} = {1}", "Item", e.Item);
			messageBoxVB.AppendLine();
			messageBoxVB.AppendFormat("{0} = {1}", "ToolStrip", e.ToolStrip);
			messageBoxVB.AppendLine();
			MessageBox.Show(messageBoxVB.ToString(), "RenderItemBackground Event");
		}
		
		private void MenuSkin_RenderItemText(object sender, System.Windows.Forms.ToolStripItemTextRenderEventArgs e)
		{
			TLeft = e.TextRectangle.Left;
		}
		
		private void MenuSkin_RenderMenuItemBackground(object sender, System.Windows.Forms.ToolStripItemRenderEventArgs e)
		{
			if (mAttachSkin == false)
			{
				return;
			}
			Graphics g = e.Graphics;
			ToolStripItem mItem = e.Item;
			//  g.FillRectangle(New SolidBrush(mItemColor1), mItem.Bounds)
		}
		
		
		
		private void MenuSkin_RenderToolStripBorder(object sender, System.Windows.Forms.ToolStripRenderEventArgs e)
		{
			if (mAttachSkin == false)
			{
				return;
			}
			Graphics g = e.Graphics;
			g.DrawRectangle(new Pen(mMenuBorderColor), new Rectangle(e.AffectedBounds.Left, e.AffectedBounds.Top, e.AffectedBounds.Width - 1, e.AffectedBounds.Height - 1));
		}
		protected override void OnRenderItemCheck(System.Windows.Forms.ToolStripItemImageRenderEventArgs e)
		{
			e.Graphics.DrawImage(mMenuCheck, e.ImageRectangle.Location);
			return ;
//			base.OnRenderItemCheck(e);
			
		}
		protected override void OnRenderItemImage(System.Windows.Forms.ToolStripItemImageRenderEventArgs e)
		{
			e.Graphics.SmoothingMode = SmoothingMode.HighQuality;
			base.OnRenderItemImage(e);
		}
		
		protected override void OnRenderImageMargin(System.Windows.Forms.ToolStripRenderEventArgs e) //绘制左侧背景
		{
			Rectangle LRect = e.AffectedBounds;
			LinearGradientBrush LBrush = new LinearGradientBrush(LRect, mBackLeftColor1, mBackLeftColor2, LinearGradientMode.Horizontal);
			ColorBlend ColorL = new ColorBlend();
			ColorL.Colors = new Color[] {mBackLeftColor1, mBackLeftColor2, mBackLeftColor3, mBackLeftColor4};
			ColorL.Positions = new Single[] {0 / 3.0F, 1 / 3.0F, 2 / 3.0F, 3 / 3.0F};
			LBrush.InterpolationColors = ColorL;
			TLeft = LRect.Right;
			e.Graphics.FillRectangle(LBrush, LRect);
			e.Graphics.DrawLine(new Pen(mSeparator), LRect.Right, LRect.Top, LRect.Right, LRect.Bottom);
			base.OnRenderImageMargin(e);
		}
		protected override void OnRenderToolStripPanelBackground(System.Windows.Forms.ToolStripPanelRenderEventArgs e)
		{
			e.Handled = true;
			base.OnRenderToolStripPanelBackground(e);
		}
		protected override void OnRenderDropDownButtonBackground(System.Windows.Forms.ToolStripItemRenderEventArgs e)
		{
			
			base.OnRenderDropDownButtonBackground(e);
		}
		protected override void OnRenderArrow(System.Windows.Forms.ToolStripArrowRenderEventArgs e) //Menu_Arrow
		{
			//  e.Graphics.FillRectangle(New SolidBrush(Color.Blue), e.ArrowRectangle)
			base.OnRenderArrow(e);
		}
		//================================================================================
		protected override void OnRenderToolStripBackground(ToolStripRenderEventArgs e)
		{
			ToolStrip ToolObj = e.ToolStrip;
			if (ToolObj.IsDropDown)
			{
				e.Graphics.FillRectangle(new SolidBrush(mMenuBackColor), e.AffectedBounds);
			}
			else
			{
				Rectangle gRect = e.AffectedBounds;
				LinearGradientBrush Brush1 = new LinearGradientBrush(gRect, mMenuBarColor1, mMenuBarColor2, LinearGradientMode.Vertical);
				ColorBlend ColorB = new ColorBlend();
				ColorB.Colors = new Color[] {mMenuBarColor1, mMenuBarColor2, mMenuBarColor3, mMenuBarColor4};
				ColorB.Positions = new Single[] {0 / 3.0F, 1 / 3.0F, 2 / 3.0F, 3 / 3.0F};
				Brush1.InterpolationColors = ColorB;
				e.Graphics.FillRectangle(Brush1, gRect);
				Brush1.Dispose();
			}
			
			return ;
//			base.OnRenderToolStripBackground(e);
		}
		protected override void OnRenderMenuItemBackground(System.Windows.Forms.ToolStripItemRenderEventArgs e)
		{
			ToolStrip ToolStrip = e.ToolStrip;
			ToolStripItem Item = e.Item;
			if (Item.Enabled == false)
			{
				return ;
			}
			Graphics g = e.Graphics;
			g.SmoothingMode = SmoothingMode.HighQuality;
			Rectangle Rect = new Rectangle(2, 0, e.Item.Size.Width - 4, e.Item.Size.Height - 1);
			GraphicsPath gPath = CreateRoundPath(Rect, mR);
			if (Item.Selected && e.Item.Pressed == false)
			{
				LinearGradientBrush ItemBrush = new LinearGradientBrush(Rect, mItemColor1, mItemColor1, LinearGradientMode.Vertical);
				ColorBlend ColorI = new ColorBlend();
				ColorI.Colors = new Color[] {mItemColor1, mItemColor2, mItemColor3, mItemColor4, mItemColor5};
				ColorI.Positions = new Single[] {0 / 4.0F, 1 / 4.0F, 2 / 4.0F, 3 / 4.0F, 4 / 4.0F};
				ItemBrush.InterpolationColors = ColorI;
				g.FillPath(ItemBrush, gPath);
				g.DrawPath(new Pen(mItemBorderColor), gPath);
			}
			else if (Item.Selected && e.Item.Pressed == true)
			{
				LinearGradientBrush ItemBrush = new LinearGradientBrush(Rect, mItemDownColor1, mItemDownColor1, LinearGradientMode.Vertical);
				ColorBlend ColorI = new ColorBlend();
				ColorI.Colors = new Color[] {mItemDownColor1, mItemDownColor2, mItemDownColor3, mItemDownColor4, mItemDownColor5};
				ColorI.Positions = new Single[] {0 / 4.0F, 1 / 4.0F, 2 / 4.0F, 3 / 4.0F, 4 / 4.0F};
				ItemBrush.InterpolationColors = ColorI;
				g.FillPath(ItemBrush, gPath);
				g.DrawPath(new Pen(mItemBorderColor), gPath);
			}
			gPath.Dispose();
			// End If
			base.OnRenderMenuItemBackground(e);
		}
		protected override void OnRenderSeparator(System.Windows.Forms.ToolStripSeparatorRenderEventArgs e) //绘制分割线
		{
			e.Graphics.DrawLine(new Pen(mSeparator), new Point(TLeft, 0), new Point(e.Item.Size.Width, 0));
			base.OnRenderSeparator(e);
		}
		public object CreateRoundPath(Rectangle Rect, int R)
		{
			GraphicsPath ResultPath = new GraphicsPath(FillMode.Alternate);
			int L = 2 * R;
			Rectangle TmpRect = new Rectangle(Rect.Location, new Size(L, L));
			ResultPath.AddArc(TmpRect, 180.0F, 90.0F);
			ResultPath.AddLine(new Point(Rect.Left + R, Rect.Top), new Point(Rect.Right - R, Rect.Top));
			TmpRect.X = Rect.Right - L;
			ResultPath.AddArc(TmpRect, 270.0F, 90.0F);
			ResultPath.AddLine(new Point(Rect.Right, Rect.Top + R), new Point(Rect.Right, Rect.Bottom - R));
			TmpRect.Y = Rect.Bottom - L;
			ResultPath.AddArc(TmpRect, 0.0F, 90.0F);
			ResultPath.AddLine(new Point(Rect.Right - R, Rect.Bottom), new Point(Rect.Left + R, Rect.Bottom));
			TmpRect.X = Rect.Left;
			ResultPath.AddArc(TmpRect, 90.0F, 90.0F);
			ResultPath.AddLine(new Point(Rect.Left, Rect.Bottom - R), new Point(Rect.Left, Rect.Top + R));
			return ResultPath;
		}
	}
	
}
